package com.qj.daibei.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qj.daibei.mapper.UserMapper;
import com.qj.daibei.pojo.User;
import com.qj.daibei.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * author zyc
 * Created by sugar zhang on 2021/9/22 12:59
 */
@Service
public class UserServiceImpl  extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    UserMapper mapper;

    @Override
    public User login(String username, String password) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .eq("user_name", username)
                .eq("password", password);
        return this.mapper.selectOne(queryWrapper);
    }

    // wml根据用户id查询该用户是否填写完个人信息
    @Override
    public User queryForFillInById(Integer id) {
        return this.mapper.selectById(id);
    }

    // wml根据用户id修改该用户信息
    @Override
    public int updateByUserId(User user) {
        UpdateWrapper<User> userUpdateWrapper = new UpdateWrapper<>();
        userUpdateWrapper.eq("user_id", user.getUserId());
        return this.mapper.update(user, userUpdateWrapper);
    }
}
